/**
 *     This file is part of cesm-ws.
 *
 *     cesm-ws, Web Service for Community Earth System Model
 *
 *     Copyright (c) 2010, Purdue University and/or affilicates or thrid-party contributors as
 *     indicated by the @author tags or express copyright attribution statements
 *     applied by the authors. All third-party contributions are distributed under
 *     license by Purdue University.
 *
 *     cesm-ws is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this distribution.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.purdue.rcac.cesm.persistence.dao;

import java.util.List;

import org.jboss.ejb3.annotation.Management;

import edu.purdue.rcac.cesm.persistence.model.CESMCaseConfig;
import edu.purdue.rcac.cesm.persistence.model.CESMCaseRuntime;

/**
 * Management interface definition
 * 
 * @author Han Zhang
 * 
 */
@Management
public interface CaseManager {

	public static final String OBJECT_NAME = "cesm.persistence:service=CaseManager";

	/**
	 * Management methods
	 */
	void create() throws Exception;

	void start() throws Exception;

	void stop();

	void destroy();

	/**
	 * DAO methods
	 */
	// checks if a CCSM4CaseConfigConfig object has been managed
	public boolean exists(String username, String casename);

	// persist object
	public void save(CESMCaseConfig caseConfig);

	public void save(CESMCaseRuntime caseRuntime);

	// updates changes into database
	public void merge(CESMCaseConfig caseConfig);

	public void merge(CESMCaseRuntime caseRuntime);

	// deletes an object
	public void remove(CESMCaseConfig caseConfig);

	public void remove(CESMCaseRuntime caseRuntime);

	public void refresh(CESMCaseConfig caseConfig);

	/**
	 * @param id
	 *            Long typed id
	 * @return managed CCSM4CaseConfig object if found, otherwise return null
	 */
	public CESMCaseConfig findById(Long id);

	/**
	 * @param pbsid
	 *            pbs id string
	 * @return managed CCSM4CaseRuntime object if found, otherwise return null
	 */
	public CESMCaseRuntime findByPbsid(String pbsid);

	/**
	 * @param owner
	 *            name of user
	 * @param casename
	 *            name of case
	 * @return managed CCSM4CaseConfig object if found, otherwise return null
	 */
	public CESMCaseConfig findByOwnerAndName(String owner, String casename);

	/**
	 * @param owner
	 *            name of user
	 * @return list of managed CCSM4CaseConfig objects if found, otherwise
	 *         return null
	 */
	public List<CESMCaseConfig> findByOwner(String owner);

	/**
	 * @return a list of case runtimes that has neither DONE, DELETED or
	 *         COMPLETED_OR_DELETED job status
	 */
	public List<CESMCaseRuntime> listAllUnfinishedRuntimes();
	
	public List<CESMCaseRuntime> findByCaseConfigId(long cid);
	
	public List<CESMCaseConfig> listAllRunningCases();
}
